{{!
  Copyright IBM Corp. 2016, 2025
  SPDX-License-Identifier: BUSL-1.1
}}
<Page::Header @title={{@model.name}}>
  <:breadcrumbs>
    <Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} />
  </:breadcrumbs>
  <:actions>
    <Hds::Dropdown as |D|>
      <D.ToggleButton @text="Manage" @color="secondary" data-test-dropdown="Manage" />
      {{#if @model.canEdit}}
        <D.Interactive @icon="edit" @route="roles.role.edit" data-test-popup-menu="Edit role">Edit role</D.Interactive>
      {{/if}}
      {{#if @model.canRotateStaticCreds}}
        <D.Interactive
          @icon="rotate-cw"
          {{on "click" (fn (mut this.showConfirmRotateModal) true)}}
          data-test-popup-menu="Rotate credentials"
        >Rotate credentials</D.Interactive>
      {{/if}}
      {{#if @model.canDelete}}
        <D.Interactive
          @color="critical"
          @icon="trash"
          {{on "click" (fn (mut this.showConfirmDeleteModal) true)}}
          data-test-popup-menu="Delete role"
        >Delete role</D.Interactive>
      {{/if}}
    </Hds::Dropdown>
    {{#if @model.canReadCreds}}
      <Hds::Button @text="Get credentials" @route="roles.role.credentials" data-test-button="Get credentials" />
    {{/if}}
  </:actions>
</Page::Header>

{{#each @model.displayFields as |field|}}
  {{#let (get @model field.name) as |value|}}
    <InfoTableRow
      data-test-filtered-field
      @label={{or field.options.detailsLabel field.options.label}}
      @value={{if (eq field.options.editType "ttl") (format-duration value) value}}
    />
  {{/let}}
{{/each}}

{{#if this.showConfirmDeleteModal}}
  <ConfirmModal
    @color="critical"
    @confirmMessage="You will not be able to recover it later."
    @confirmTitle="Are you sure?"
    @onClose={{fn (mut this.showConfirmDeleteModal) false}}
    @onConfirm={{this.delete}}
  />
{{/if}}

{{#if this.showConfirmRotateModal}}
  <ConfirmModal
    @color="warning"
    @confirmMessage="When manually rotating credentials, the rotation period will start over."
    @confirmTitle="Rotate credentials?"
    @onClose={{fn (mut this.showConfirmRotateModal) false}}
    @onConfirm={{perform this.rotateCredentials}}
  />
{{/if}}